package com.amazonaws.services.iot.client.sample.pubSub;


import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendMail {

    /**
     * @param args
     * @throws Exception 
     */
	
  	
    public   int token(String s) {
  	    	String str=s.trim();
  	    	String str2="";
  	    	if(str != null && !"".equals(str)){
  	    	for(int i=0;i<str.length();i++){
  	    	if(str.charAt(i)>=48 && str.charAt(i)<=57){
  	    	str2+=str.charAt(i);
  	    	}
  	    	}

  	    	}
  	    	return  Integer.parseInt(str2);
  	    	}
    
    public  void send() throws Exception{
  
        
        Properties prop = new Properties();
        prop.setProperty("mail.host", "smtp.126.com");
        prop.setProperty("mail.transport.protocol", "smtp");
        prop.setProperty("mail.smtp.auth", "true");
      
        Session session = Session.getInstance(prop);
        
        session.setDebug(true);
       
        Transport ts = session.getTransport();
      
        ts.connect("smtp.126.com", "zfhefd2015", "123456zf");
       
        Message message = createSimpleMail(session);
       
        ts.sendMessage(message, message.getAllRecipients());
        
        ts.close();
    }
    
  
    public static MimeMessage createSimpleMail(Session session)
            throws Exception {
        
        MimeMessage message = new MimeMessage(session);
        
        message.setFrom(new InternetAddress("zfhefd2015@126.com"));
        
        message.setRecipient(Message.RecipientType.TO, new InternetAddress("zfhefd2015@126.com"));
        
        message.setSubject("This email comes from IoT_Test");
      
        message.setContent("Hello!!!!!", "text/html;charset=UTF-8");
       
        return message;
    }
}